package com.kefu.web.im.netty.client;

import java.util.List;

import com.corundumstudio.socketio.SocketIOClient;

public class NettyClients {

	private static NettyClients clients = new NettyClients();

	private IMClientPool imClients = new IMClientPool();
	private SeatClientPool seatClients = new SeatClientPool();
	private IMClientPool entIMClients = new IMClientPool();

	public static NettyClients getInstance() {
		return clients;
	}

	public void setImClients(IMClientPool imClients) {
		this.imClients = imClients;
	}

	public void putIMEventClient(String id, SocketIOClient userClient) {
		imClients.putClient(id, userClient);
	}

	public void removeIMEventClient(String id, String sessionid) {
		imClients.removeClient(id, sessionid);
	}

	public void sendIMEventMessage(String id, String event, Object data) {
		List<SocketIOClient> userClients = imClients.getClients(id);
		for (SocketIOClient userClient : userClients) {
			userClient.sendEvent(event, data);
		}
	}

	public void setSeatClients(SeatClientPool seatClients) {
		this.seatClients = seatClients;
	}

	public void putSeatEventClient(String id, SocketIOClient seatClient) {
		seatClients.putClient(id, seatClient);
	}

	public void removeSeatEventClient(String id, String sessionid) {
		seatClients.removeClient(id, sessionid);
	}

	public void sendSeatEventMessage(String id, String event, Object data) {
		List<SocketIOClient> seats = seatClients.getClients(id);
		for (SocketIOClient seat : seats) {
			seat.sendEvent(event, data);
		}
	}

	public void setEntImClients(IMClientPool entIMClients) {
		this.entIMClients = entIMClients;
	}

	public void putEntIMEventClient(String id, SocketIOClient userClient) {
		entIMClients.putClient(id, userClient);
	}

	public void removeEntIMEventClient(String id, String sessionid) {
		entIMClients.removeClient(id, sessionid);
	}

	public void sendEntIMEventMessage(String id, String event, Object data) {
		List<SocketIOClient> entims = entIMClients.getClients(id);
		for (SocketIOClient userClient : entims) {
			userClient.sendEvent(event, data);
		}
	}

	public int getEntIMClientsNum(String user) {
		return entIMClients.getClients(user) != null ? entIMClients.getClients(user).size() : 0;
	}
}
